import VueRouter from 'vue-router'

// 导入对应的路由组件
import HomeContainer from './components/tabbar/HomeContainer.vue'
import MemberContainer from './components/tabbar/MemberContainer.vue'
import OrderContainer from './components/tabbar/OrderContainer.vue'
import SearchContainer from './components/tabbar/SearchContainer.vue'
import Login from './components/tabbar/Login.vue'

// 3. 创建路由对象
var router = new VueRouter({
  routes: [ // 配置路由规则
    { path: '/', redirect: '/home' },
    { path: '/home', component: HomeContainer },
    { path: '/member', component: MemberContainer },
    { path: '/order', component: OrderContainer },
    { path: '/search', component: SearchContainer },
    { path: '/login', component: Login }
  ],
  linkActiveClass: 'mui-active' // 覆盖默认的路由高亮的类，默认的类叫做 router-link-active
})

/* router.beforeEach((to, from, next) => {
  //获取本地储存的id
  let userId = localStorage.getItem('user_Id');
  //进入下列路由需要凭证
  let needIdList = ['member', 'order'];

  if (needIdList.indexOf(to.name) > -1) {
    if (userId === null) {
      
      next({
        path: '/login',
      })
    }
    else {
      next();
    }
  }
  else {
    if (to.name === 'login' && userId != null) {
      next({
        path: '/member',
      })
    }
    else {
      next();
    }
  }
}) */

// 把路由对象暴露出去
export default router